home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / decode_pcanywhere.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-17  |  1.3 KB  |  65 lines

  1. /*
  2.   decode_pcanywhere.c
  3.  
  4.   Symantec pcAnywhere.
  5.  
  6.   Thanks to Pascal Longpre <longprep@HOTMAIL.COM> for his BUGTRAQ post
  7.   on pcAnywhere encryption, and for providing me with traffic traces.
  8.   
  9.   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  10.   
  11.   $Id: decode_pcanywhere.c,v 1.2 2000/05/17 06:03:17 dugsong Exp $
  12. */
  13.  
  14. #include <sys/types.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include "decode.h"
  18.  
  19. int
  20. decode_pcanywhere(u_char *buf, int len)
  21. {
  22.     u_char *p, *end;
  23.     int i;
  24.     
  25.     Buf[0] = '\0';
  26.     
  27.     if (len < 6 || *(u_long *)buf != 0)
  28.         return (0);
  29.     
  30.     /* Version 7, no encryption. */
  31.     if (buf[4] != 0x8d) {
  32.         buf[len - 1] = '\0';
  33.         if ((p = strchr(buf + 4, 0x6f)) != NULL) *p = '\0';
  34.         
  35.         for (p = strtok(buf + 5, "\r"); p; p = strtok(NULL, "\r")) {
  36.             strlcat(Buf, p, sizeof(Buf));
  37.             strlcat(Buf, "\n", sizeof(Buf));
  38.         }
  39.         return (strlen(Buf));
  40.     }
  41.     /* Version 9, lame encryption. */
  42.     end = buf + len;
  43.     for (p = buf + 5; end - p > 2; p++) {
  44.         if (*p++ != 0x06)
  45.             break;
  46.         
  47.         if (p > end || *p > 56 || end - p - 1 < *p)
  48.             break;
  49.         
  50.         for (i = *p++ - 1; i > 0; i--)
  51.             p[i] = p[i-1] ^ p[i] ^ (i - 1);
  52.         p[0] ^= 0xab;
  53.         
  54.         i = *--p; memmove(p, p + 1, i); p[i] = '\0';    /* i suk */
  55.         
  56.         if (is_ascii_string(p, i)) {
  57.             strlcat(Buf, p, sizeof(Buf));
  58.             strlcat(Buf, "\n", sizeof(Buf));
  59.         }
  60.         p += i;
  61.     }
  62.     return (strlen(Buf));
  63. }
  64.  
  65.